package com.ruoyi.teacher.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.utils.ServletUtils;
import com.ruoyi.common.security.utils.SecurityUtils;
import com.ruoyi.system.api.model.LoginUser;
import com.ruoyi.teacher.dto.RosteringDto;
import com.ruoyi.teacher.vo.GroupVo;
import com.ruoyi.teacher.vo.RosteringVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.teacher.domain.TTeacherRostering;
import com.ruoyi.teacher.service.ITTeacherRosteringService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 老师排班Controller
 * 
 * @author ruoyi
 * @date 2022-12-26
 */
@RestController
@RequestMapping("/rostering")
public class TTeacherRosteringController extends BaseController
{
    @Autowired
    private ITTeacherRosteringService tTeacherRosteringService;

    /**
     * 查询老师排班列表
     */
    @RequiresPermissions("teacher:rostering:list")
    @GetMapping("/list")
    public TableDataInfo list(TTeacherRostering tTeacherRostering)
    {
        startPage();
        List<TTeacherRostering> list = tTeacherRosteringService.selectTTeacherRosteringList(tTeacherRostering);
        return getDataTable(list);
    }

    /**
     * 导出老师排班列表
     */
    @RequiresPermissions("teacher:rostering:export")
    @Log(title = "老师排班", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TTeacherRostering tTeacherRostering)
    {
        List<TTeacherRostering> list = tTeacherRosteringService.selectTTeacherRosteringList(tTeacherRostering);
        ExcelUtil<TTeacherRostering> util = new ExcelUtil<TTeacherRostering>(TTeacherRostering.class);
        util.exportExcel(response, list, "老师排班数据");
    }

    /**
     * 获取老师排班详细信息
     */
    @RequiresPermissions("teacher:rostering:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tTeacherRosteringService.selectTTeacherRosteringById(id));
    }

    /**
     * 新增老师排班
     */
    @RequiresPermissions("teacher:rostering:add")
    @Log(title = "老师排班", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TTeacherRostering tTeacherRostering)
    {
        return toAjax(tTeacherRosteringService.insertTTeacherRostering(tTeacherRostering));
    }

    /**
     * 修改老师排班
     */
    @RequiresPermissions("teacher:rostering:edit")
    @Log(title = "老师排班", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TTeacherRostering tTeacherRostering)
    {
        return toAjax(tTeacherRosteringService.updateTTeacherRostering(tTeacherRostering));
    }

    /**
     * 删除老师排班
     */
    @RequiresPermissions("teacher:rostering:remove")
    @Log(title = "老师排班", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tTeacherRosteringService.deleteTTeacherRosteringByIds(ids));
    }

    /**
     * 更新老师排班详细信息
     */
    @RequiresPermissions("teacher:rostering:updateRoster")
    @GetMapping("/updateRoster")
    public AjaxResult updateRoster()
    {
        return success(tTeacherRosteringService.updateRoster());
    }

    /**
     * 获取用户排班信息
     * @return
     */
    @RequiresPermissions("teacher:rostering:userGroupInfo")
    @GetMapping("/userGroupInfo")
    public List<GroupVo> getUserGroupInfo()
    {
        return tTeacherRosteringService.getUserGroupInfo();
    }

    /**
     * 排班
     * @return
     */
    @RequiresPermissions("teacher:rostering:rostering")
    @PostMapping("/rostering")
    public AjaxResult rostering(@RequestBody RosteringDto rosteringDto)
    {
        return success(tTeacherRosteringService.rostering(rosteringDto));
    }

    /**
     * 获取排班列表
     * @return
     */
    @RequiresPermissions("teacher:rostering:rosteringList")
    @GetMapping("/rosteringList")
    public List<RosteringVo> getRosteringList(TTeacherRostering tTeacherRostering)
    {
        return tTeacherRosteringService.getRosteringList(tTeacherRostering);
    }

    @GetMapping("/teacherNameList")
    public List<String> getTeacherNameList()
    {
        return tTeacherRosteringService.getTeacherNameList();
    }
}
